#!/bin/bash

# 设置颜色输出
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# 获取项目根目录
PROJECT_ROOT=$(cd "$(dirname "$0")/../.." && pwd)
DEPLOY_DIR="$PROJECT_ROOT/mcphub-scripts/deploy"

echo -e "${GREEN}==== MCPRepoMarket 服务停止脚本 ====${NC}"

# 停止后端服务
echo -e "\n${GREEN}停止后端服务...${NC}"
if [ -f "$DEPLOY_DIR/backend.pid" ]; then
    PID=$(cat "$DEPLOY_DIR/backend.pid")
    if kill -0 "$PID" 2>/dev/null; then
        kill "$PID"
        echo -e "${GREEN}后端服务已停止 (PID: $PID)${NC}"
    else
        echo -e "${YELLOW}后端服务已不在运行${NC}"
    fi
    rm -f "$DEPLOY_DIR/backend.pid"
else
    pkill -f "gunicorn"
    echo -e "${GREEN}后端服务已停止${NC}"
fi

echo -e "\n${GREEN}所有服务已停止！${NC}" 